<script setup lang="ts">
import { ref } from 'vue'

const formData = ref({
    name: '',
    idCard: '',
    phone: '',
    verifyCode: '',
    password: '',
    confirmPassword: ''
})

const showPassword = ref(false)
const showConfirmPassword = ref(false)
const countdown = ref(0)

const sendVerifyCode = () => {
    if (countdown.value > 0) return
    if (!formData.value.phone) {
        alert('请先输入手机号码')
        return
    }
    // 发送验证码逻辑
    countdown.value = 60
    const timer = setInterval(() => {
        countdown.value--
        if (countdown.value <= 0) {
            //清除这个定时器
            clearInterval(timer)
        }
    }, 1000)
}

const handleSubmit = () => {
    // 表单验证
    if (!formData.value.name) {
        alert('请输入姓名')
        return
    }
    if (!formData.value.idCard) {
        alert('请输入身份证号')
        return
    }
    if (!formData.value.phone) {
        alert('请输入手机号')
        return
    }
    if (!formData.value.verifyCode) {
        alert('请输入验证码')
        return
    }
    if (!formData.value.password) {
        alert('请设置密码')
        return
    }
    if (formData.value.password !== formData.value.confirmPassword) {
        alert('两次输入的密码不一致')
        return
    }

    // 提交注册信息
    console.log('提交注册信息', formData.value)
}
</script>

<template>
    <div class="register-user-page">
        <div class="register-header">
            <h1>用户注册</h1>
            <p class="sub-title">注册就诊卡账号</p>
        </div>

        <div class="register-form">
            <!-- 姓名输入 -->
            <div class="form-item">
                <label>姓名</label>
                <input type="text" v-model="formData.name" placeholder="请输入您的真实姓名">
            </div>

            <!-- 身份证号输入 -->
            <div class="form-item">
                <label>身份证号</label>
                <input type="text" v-model="formData.idCard" placeholder="请输入您的身份证号">
            </div>

            <!-- 手机号输入 -->
            <div class="form-item">
                <label>手机号</label>
                <input type="tel" v-model="formData.phone" placeholder="请输入手机号码">
            </div>

            <!-- 验证码输入 -->
            <div class="form-item verify-code">
                <label>验证码</label>
                <div class="verify-input-group">
                    <input type="text" v-model="formData.verifyCode" placeholder="请输入验证码">
                    <button @click="sendVerifyCode" :disabled="countdown > 0" class="verify-button">
                        {{ countdown > 0 ? `${countdown}秒后重新获取` : '获取验证码' }}
                    </button>
                </div>
            </div>

            <!-- 密码输入 -->
            <div class="form-item">
                <label>设置密码</label>
                <div class="password-input">
                    <input :type="showPassword ? 'text' : 'password'" v-model="formData.password" placeholder="请设置登录密码">
                    <span class="toggle-password" @click="showPassword = !showPassword">
                        {{ showPassword ? '隐藏' : '显示' }}
                    </span>
                </div>
            </div>

            <!-- 确认密码 -->
            <div class="form-item">
                <label>确认密码</label>
                <div class="password-input">
                    <input :type="showConfirmPassword ? 'text' : 'password'" v-model="formData.confirmPassword"
                        placeholder="请再次输入密码">
                    <span class="toggle-password" @click="showConfirmPassword = !showConfirmPassword">
                        {{ showConfirmPassword ? '隐藏' : '显示' }}
                    </span>
                </div>
            </div>

            <!-- 注册按钮 -->
            <button class="submit-button" @click="handleSubmit">
                立即注册
            </button>

            <!-- 已有账号提示 -->
            <div class="login-hint">
                已有账号？ <router-link to="/ProfilePage">立即登录</router-link>
            </div>

            <!-- 帮助提示 -->
            <div class="help-tips">
                <p>注册遇到问题？</p>
                <p>请拨打咨询电话：0123-4567890</p>
            </div>
        </div>
    </div>
</template>

<style scoped>
.register-user-page {
    padding: 20px;
    background-color: #f5f5f5;
    min-height: 100vh;
}

.register-header {
    text-align: center;
    margin-bottom: 30px;
}

.register-header h1 {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.sub-title {
    font-size: 16px;
    color: #666;
}

.register-form {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-item {
    margin-bottom: 25px;
}

.form-item label {
    display: block;
    font-size: 18px;
    color: #333;
    margin-bottom: 10px;
}

.form-item input {
    width: 85%;
    padding: 15px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background-color: white;
}

.verify-input-group {
    display: flex;
    gap: 10px;
}

.verify-input-group input {
    flex: 1;
}

.verify-button {
    padding: 0 15px;
    font-size: 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    white-space: nowrap;
}

.verify-button:disabled {
    background-color: #cccccc;
}

.password-input {
    position: relative;
}

.toggle-password {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-color);
    font-size: 16px;
    cursor: pointer;
}

.submit-button {
    width: 100%;
    padding: 15px;
    font-size: 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    margin-top: 20px;
}

.login-hint {
    text-align: center;
    margin-top: 20px;
    font-size: 16px;
    color: #666;
}

.login-hint a {
    color: var(--primary-color);
    text-decoration: none;
}

.help-tips {
    margin-top: 30px;
    padding: 15px;
    background-color: #f8f8f8;
    border-radius: 8px;
    text-align: center;
}

.help-tips p {
    margin: 5px 0;
    color: #666;
    font-size: 16px;
}

/* 输入框焦点样式 */
input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* 错误提示样式 */
.error-message {
    color: #ff4444;
    font-size: 14px;
    margin-top: 5px;
}
</style>